package org.mycub.server.mock.services;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mycub.server.mock.bike.factories.StationsLightFactory;
import org.mycub.server.mock.bike.models.StationsListLight;

import com.google.gson.Gson;

@SuppressWarnings("serial")
public class MockBikeLightService extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		String lonString = request.getParameter("lon");
		String latString = request.getParameter("lat");
		String radiusString = request.getParameter("rad");

		double lon = new Double(lonString).doubleValue();
		double lat = new Double(latString).doubleValue();
		double radius = new Double(radiusString).doubleValue();

		StationsListLight stationList = new StationsLightFactory().createStationsList(
				lon, lat, radius);

		Gson gson = new Gson();

		PrintWriter out = response.getWriter();

		out.println(gson.toJson(stationList));
	}
}